package com.yunze.system.service.impl.yunze.install;

import com.yunze.common.mapper.mysql.install.YzInstallPlacefloorMapper;
import com.yunze.common.mapper.mysql.install.YzInstallPlacemanageMapper;
import com.yunze.common.utils.yunze.PageUtil;
import com.yunze.system.service.yunze.install.YzInstallPlacemanageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class YzInstallPlacemanageServiceImpl implements YzInstallPlacemanageService {

    @Resource
    private YzInstallPlacemanageMapper yzInstallPlacemanageMapper;
    @Resource
    private YzInstallPlacefloorMapper yzInstallPlacefloorMapper;

    @Override
    public Map<String, Object> PstrMap(Map map) {
        Map<String, Object> omp = new HashMap<String, Object>();
        Integer currenPage = map.get("pageNum") != null ? Integer.parseInt(map.get("pageNum").toString()) : 0;
        Integer pageSize = map.get("pageSize") != null ? Integer.parseInt(map.get("pageSize").toString()) : 10;
        Integer rowCount = yzInstallPlacemanageMapper.selMapCount(map);
        rowCount = rowCount != null ? rowCount : 0;
        PageUtil pu = new PageUtil(rowCount, currenPage, pageSize);//初始化分页工具类

        //数据打包
        map.put("StarRow", pu.getStarRow());
        map.put("PageSize", pu.getPageSize());
        omp.put("Pu", pu);

        List<Map<String, Object>> Datalist = yzInstallPlacemanageMapper.selMap(map);
        omp.put("Data", Datalist);
        return omp;
    }

    @Override
    public boolean add(Map map) {
        boolean bool = false;

        Integer added = yzInstallPlacemanageMapper.add(map);
        if(added > 0){
         try {
            //循环添加楼层
            String Number =map.get("number_floor").toString();
            int integerEmpId2 = Integer.valueOf(Number);
            List<Object> list = new ArrayList<>();
            for (int i = 1; i < integerEmpId2+1; i ++) {
                Map<String,Object> objectMap = new HashMap<>();
                objectMap.put("id",map.get("id"));
                objectMap.put("y_floor",i+"楼");
                objectMap.put("create_time",map.get("create_time"));
                list.add(objectMap);
            }
            Map<String,Object> Rmap = new HashMap<>();
            Rmap.put("floArr",list);

            bool = yzInstallPlacefloorMapper.arrFllor(Rmap);
         }catch (Exception e){
             System.out.println("批量添加楼层 ！ 操作失败"+e.getMessage());
         }
      }
        return bool;
    }

    @Override
    public boolean delId(Map map) {
        return yzInstallPlacemanageMapper.delId(map) > 0;
    }

    @Override
    public boolean upd(Map map) {
        return yzInstallPlacemanageMapper.updForm(map) > 0;
    }



}
